<template>
  <div>
    <m-mask :show="show"></m-mask>
    <div class="flex" :style="{pointerEvents:show?'auto':'none'}" @click.self="_close()">
      <transition name="trans">
        <div class="MModal" v-if="show">
          <slot></slot>
        </div>
      </transition>
    </div>
  </div>
</template>

<style lang="less" scoped>
    @import "~core/basic.less";

    .flex{
      position: fixed;
      width: 100%;
      height: 100%;
      left: 0px;
      top: 0px;
      z-index: @top - 1;
      display: flex;
      justify-content: center;
      align-items: center;
      text-align: center;
      overflow: auto;
    }

    .MModal {
      position: relative;
      background: @white;
      z-index: @top;
      box-shadow: @shadow-3;

      .noselect();
    }

    .trans-enter-active, .trans-leave-active {
      transition: all 500ms;
      transform: translate(0px,0px);
      transition-timing-function: @ease-strong;
    }
    .trans-enter, .trans-leave-active {
      opacity: 0;
      transform: translate(0px,50px);
    }
</style>

<script>
  export default {
    props:{
      show:{
        default:false
      },
      name: {
        type:String,
        required:true
      },
      close:{
        default:true
      }
    },
    methods:{
      _close:function(){
        if(!!this.close){
          this.show=false;
        }
      }
    },
    mounted:function(){
      this.name && this.mirror.instance.set("modal_"+this.name,this);
    }
  }
</script>